feat: 支持 Push 和 Release 事件通知及 Webhook 解析修复#6
Merged
Conversation
Soulter
approved these changes
Jun 13, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
该 PR 在现有 GitHub Cards 插件基础上,新增对 Push 与 Release 事件的通知支持,并增强 Webhook 在 application/x-www-form-urlencoded 场景下的 payload 解析兼容性,同时扩展轮询逻辑以抓取 commits/releases。
Changes:
- Webhook:兼容
application/x-www-form-urlencoded(从request.form["payload"]提取 JSON)。 - 轮询:
_fetch_new_items扩展为同时抓取 Issue/PR、Commits、Releases,并在通知侧识别新类型。 - 格式化:新增 Push/Release Webhook 消息格式化函数;插件元数据版本号更新。
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
| webhook_server.py | 增强 Webhook 请求体解析,兼容表单编码 payload。 |
| main.py | 扩展轮询抓取 commits/releases、通知逻辑支持新类型,并新增 push/release Webhook 分发。 |
| formatters.py | 新增 push/release 的 Webhook 文本消息格式化。 |
| metadata.yaml | 插件版本号升级到 1.1.1。 |
Comments suppressed due to low confidence (1)
main.py:535
- new_items 按 “Issue/PR → Commits → Releases” 分段 append,最终通知顺序不是按时间排序;当一次轮询同时发现多种类型更新时,用户会看到乱序通知。建议在返回/通知前按各类型的时间戳统一排序(例如 created_at / commit.committer.date / published_at)。
if new_items:
logger.info(f"找到 {len(new_items)} 个新的 items 在 {repo}")
else:
logger.debug(f"没有找到新的 items 在 {repo}")
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| desc: GitHub 相关链接自动发送 GitHub 仓库简介/issue/pr卡片、订阅 GitHub 仓库事件 # 插件描述 | ||
| help: | ||
| version: 1.1.0 # 插件版本 | ||
| version: 1.1.1 # 插件版本 |
|
|
||
| # 3. Fetch Releases | ||
| try: | ||
| params_releases = {"per_page": 5} |
Comment on lines
+576
to
+586
| elif item["_astrbot_type"] == "release": | ||
| tag_name = item.get("tag_name", "未知版本") | ||
| name = item.get("name") or tag_name | ||
| author = item.get("author", {}).get("login", "未知") | ||
| url = item.get("html_url", "") | ||
| message = ( | ||
| f"[GitHub 更新] 仓库 {repo} 发布了新版本:\n" | ||
| f"版本: {name} ({tag_name})\n" | ||
| f"发布者: {author}\n" | ||
| f"链接: {url}" | ||
| ) |
Comment on lines
+439
to
445
| params_issues = { | ||
| "sort": "created", | ||
| "direction": "desc", | ||
| "state": "all", | ||
| "per_page": 10, | ||
| "since": last_check_dt.isoformat() + "Z", | ||
| } |
Comment on lines
+540
to
+555
| actor = (sender or {}).get("login") or "未知" | ||
|
|
||
| message_lines = [ | ||
| f"[GitHub Webhook] 仓库 {repo} 代码推送", | ||
| f"分支: {branch_or_tag}", | ||
| f"触发人: {actor}", | ||
| f"新增 {len(commits)} 个提交:" | ||
| ] | ||
|
|
||
| for commit in commits[:3]: | ||
| msg = commit.get("message", "").split("\n")[0] | ||
| sha = commit.get("id", "")[:7] | ||
| message_lines.append(f"- {sha} {msg}") | ||
|
|
||
| if len(commits) > 3: | ||
| message_lines.append(f"... 等共 {len(commits)} 个提交") |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📝 改进描述
在插件原有的基础上,增加了处理 GitHub Push (Commits) 与 Release 事件的功能。
同时修复了 Webhook 模式下当接收到
application/x-www-form-urlencoded数据时解析失败的问题。✨ 新增功能
_fetch_new_items方法现在会一并获取 Issue/PR、Commits 和 Releases。🐛 修复问题
Content-Type为application/x-www-form-urlencoded时,因为缺失字段导致的 JSON 格式解析出NoneType object has no attribute get的错误。现在会自动通过request.form获取表单中payload参数进行解析。📌 测试情况
application/json与application/x-www-form-urlencoded两种 Webhook 推送。